package mancala.listener;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import mancala.Mancala;
import mancala.model.House;


public class HouseMouseListener implements MouseListener {

    private final Mancala mancala;

    /**
     * @param mancala
     */
    public HouseMouseListener(Mancala mancala) {
        this.mancala = mancala;
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        House house = (House) e.getComponent();
        if (!house.getPlayer().isActive() || house.getStones() == 0) { // inactive pit or nothing to move
            return;
        }

        mancala.makeMove(house);
    }

    @Override
    public void mousePressed(MouseEvent e) {
        // Nothing to do
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        // Nothing to do
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        final House house = (House) e.getComponent();
        house.setToolTipText(Integer.toString(house.getStones()));
    }

    @Override
    public void mouseExited(MouseEvent e) {
        ((House) e.getComponent()).setToolTipText(null);
    }

}